package com.tastespot.listener;


import com.tastespot.model.entity.VoucherOrder;
import com.tastespot.service.IVoucherOrderService;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * @Author: 369pro
 * @CreateTime: 2025-05-24
 * @Version: 1.0
 */

@Service
public class VoucherOrderListener {

    // 为了做下单事务，我们需要调用 Service 层的 createVoucherOrder
    // 这个方法上通常会加 @Transactional、加分布式锁注解等等。
    @Resource
    private IVoucherOrderService voucherOrderService;

    @RabbitListener(queues = "seckill.orders.queue")
    public void handleMessage(VoucherOrder order) {
        // 这里调用的就是被 Spring AOP 过的代理对象
        voucherOrderService.createVoucherOrder(order.getVoucherId(), order.getUserId());
    }

    @RabbitListener(queues = "seckill.orders.queue")
    public void receiveMessage(Object message) {
        System.out.println("监听到了: " + message);
    }
}

